﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Tum.CollabXT
{
    /// <summary>
    /// Generic association class of PET.
    /// </summary>
    /// <typeparam name="TSource">Type of the source process element.</typeparam>
    /// <typeparam name="TDestination">Type of the destination process element.</typeparam>
    public class Association<TSource, TDestination> : IAssociation
        where TSource : class, IProcessElement
        where TDestination : class, IProcessElement
    {
        public string Id { get; set; }

        public string Name { get; set; }

        /// <summary>
        /// Storage for content of any type.
        /// To be used for internal temporary variables or as way to pass information from one tool provider to another.
        /// Additionally, data can be stored that is not recognized by all providers, but by some.
        /// </summary>
        public Dictionary<string, object> ExtendedData
        {
            get { return _ExtendedData; }
        }
        private readonly Dictionary<string, object> _ExtendedData = new Dictionary<string, object>();

        /// <summary>
        /// Identifier of the element this association orinated from.
        /// </summary>
        public string SourceId
        {
            get { return Source.Id; }
        }

        /// <summary>
        /// Identifier of the element this association goes to.
        /// </summary>
        public string DestinationId
        {
            get { return Destination.Id; }
        }

        /// <summary>
        /// Type of the source process element.
        /// </summary>
        public Type SourceType
        {
            get { return typeof(TSource); }
        }

        /// <summary>
        /// Type of the destination process element.
        /// </summary>
        public Type DestinationType
        {
            get { return typeof(TDestination); }
        }

        /// <summary>
        /// Description of the association.
        /// </summary>
        public string Description { get; set; }


        /// <summary>
        /// Association source process element.
        /// </summary>
        public TSource Source
        {
            get { return _Source; }
            set
            {
                if (value == null)
                    throw new ArgumentNullException();
                _Source = value;
            }
        }
        private TSource _Source;

        /// <summary>
        /// Association destination process element.
        /// </summary>
        public TDestination Destination
        {
            get { return _Destination; }
            set
            {
                if (value == null)
                    throw new ArgumentNullException();
                _Destination = value;
            }
        }
        private TDestination _Destination;


        /// <summary>
        /// Constructor.
        /// </summary>
        public Association(TSource from, TDestination to)
        {
            Source = from;
            Destination = to;
        }
    }
}
